import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:senkoo_platform/Utils/base_standard.dart';
import 'package:senkoo_platform/Utils/base_text.dart';
import 'package:senkoo_platform/Utils/hex_color_utils.dart';
import 'package:senkoo_platform/Utils/set_edge_insets.dart';
import 'package:senkoo_platform/views/equipment_modular/equipment_page.dart';

class ScheduleManagementPage extends StatefulWidget {
  const ScheduleManagementPage({
    super.key,
  });

  @override
  State<ScheduleManagementPage> createState() => _ScheduleManagementPageState();
}

class _ScheduleManagementPageState extends State<ScheduleManagementPage> {
  @override
  Widget build(BuildContext context) => Padding(
        padding: setSymEdgeInsets(horizontal: 36, vertical: 24),
        child: Column(
          children: [
            Wrap(
              runSpacing: 24.h,
              spacing: 24.w,
              children: [
                Container(
                  width: 264.w,
                  height: 40.h,
                  padding: setSymEdgeInsets(horizontal: 24),
                  decoration: BoxDecoration(
                    color: HexColor('#0C101D'),
                    borderRadius: BorderRadius.circular(40.r),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      text(
                        textString: '请选择分辨率',
                        textSize: 14.sp,
                        textColor: HexColor('#757A8A'),
                        textWeight: bold,
                      ),
                      Container(
                        width: 20.w,
                        height: 20.w,
                        color: Colors.brown,
                      )
                    ],
                  ),
                ),
                Container(
                  width: 400.w,
                  height: 40.h,
                  padding: setSymEdgeInsets(horizontal: 24),
                  decoration: BoxDecoration(
                    color: HexColor('#0C101D'),
                    borderRadius: BorderRadius.circular(40.r),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      text(
                        textString: '请输入文件名称',
                        textSize: 14.sp,
                        textColor: HexColor('#757A8A'),
                        textWeight: bold,
                      ),
                      Container(
                        width: 20.w,
                        height: 20.w,
                        color: Colors.brown,
                      )
                    ],
                  ),
                ),
                SizedBox(
                  width: 110.w,
                  height: 40.h,
                  child: AddDeviceButton(
                    textString: '添加素材',
                    onPressed: () => touchAddMaterial(),
                  ),
                ),
                Container(
                  width: 112.w,
                  height: 40.h,
                  padding: setSymEdgeInsets(horizontal: 24),
                  decoration: BoxDecoration(
                    color: HexColor('#0C101D'),
                    borderRadius: BorderRadius.circular(40.r),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      Container(
                        width: 24.w,
                        height: 24.w,
                        color: Colors.brown,
                      ),
                      Container(
                        width: 24.w,
                        height: 24.w,
                        color: Colors.brown,
                      )
                    ],
                  ),
                ),
              ],
            ),
            SizedBox(
              height: 24.h,
            ),
            Expanded(
                child: SingleChildScrollView(
              child: Wrap(
                runSpacing: 24.h,
                spacing: 24.w,
                children: _materialWidget(),
              ),
            ))
          ],
        ),
      );

  List<Widget> _materialWidget() {
    List<Widget> list = [];
    for (var i = 0; i < 10; i++) {
      list.add(Container(
        width: 171.w,
        height: 310.h,
        decoration: BoxDecoration(
            color: HexColor('#0C101D'),
            border: Border.all(width: 1.w, color: HexColor('#323236')),
            borderRadius: BorderRadius.circular(14.r),
            boxShadow: const [
              BoxShadow(
                  blurRadius: 30,
                  spreadRadius: 0,
                  offset: Offset(0, 10),
                  color: Color(0xFF0C101D)),
            ]),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Stack(
              children: [
                Container(
                  width: 159.w,
                  height: 238.h,
                  margin: setEdgeInsets(top: 6, left: 6),
                  decoration: BoxDecoration(
                      color: Colors.brown,
                      border:
                          Border.all(width: 1.w, color: HexColor('#323236')),
                      borderRadius: BorderRadius.circular(14.r),
                      boxShadow: const [
                        BoxShadow(
                            blurRadius: 30,
                            spreadRadius: 0,
                            offset: Offset(0, 10),
                            color: Color(0xFF0C101D)),
                      ]),
                ),
                Positioned(
                    bottom: 4.h,
                    right: 10.w,
                    child: Container(
                      child: text(
                          textString: "00:04:00",
                          textSize: 16.sp,
                          textColor: HexColor('#ffffff'),
                          textWeight: bold,
                          textAligin: TextAlign.left),
                    ))
              ],
            ),
            Container(
              width: 171.w,
              height: 1.h,
              margin: setEdgeInsets(top: 6, bottom: 6),
              color: HexColor('#323236'),
            ),
            Padding(
              padding: setSymEdgeInsets(horizontal: 14),
              child: text(
                  textString: "世界无烟日.avi",
                  textSize: 16.sp,
                  textColor: HexColor('#ffffff'),
                  textWeight: bold,
                  textAligin: TextAlign.left),
            ),
            Padding(
              padding: setEdgeInsets(top: 6, left: 14, right: 14),
              child: Row(
                children: [
                  text(
                      textString: "20M",
                      textSize: 14.sp,
                      textColor: HexColor('#757A8A'),
                      textWeight: bold,
                      textAligin: TextAlign.left),
                  Padding(
                    padding: setEdgeInsets(left: 14),
                    child: text(
                        textString: "1080*720",
                        textSize: 14.sp,
                        textColor: HexColor('#757A8A'),
                        textWeight: bold,
                        textAligin: TextAlign.left),
                  )
                ],
              ),
            )
          ],
        ),
      ));
    }
    return list;
  }

  Widget rowText({required String label, required String string}) => Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          text(
            textString: label,
            textSize: 14.sp,
            textColor: HexColor('#757A8A'),
            textWeight: bold,
          ),
          text(
            textString: string,
            textSize: 14.sp,
            textColor: Standard.colorFFFFFF,
            textWeight: bold,
          )
        ],
      );

  Future<void> touchAddMaterial() => showDialog(
        context: context,
        barrierColor: Standard.color000000.withOpacity(.5),
        builder: (BuildContext context) {
          return Center(
            child: Container(
              width: 600.w,
              height: 318.h,
              padding: setEdgeInsets(left: 40, right: 40, top: 28, bottom: 40),
              decoration: BoxDecoration(
                color: HexColor("#2C2C32"),
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      text(
                          textString: '添加设备',
                          textSize: 18.sp,
                          textColor: Standard.colorFFFFFF),
                      GestureDetector(
                        child: Container(
                          width: 24.w,
                          height: 24.w,
                          color: Colors.brown,
                        ),
                      )
                    ],
                  ),
                  Padding(
                    padding: setEdgeInsets(top: 24, left: 30),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Padding(
                          padding: setEdgeInsets(),
                          child: Row(
                            children: [
                              text(
                                  textString: '通讯码',
                                  textSize: 14.sp,
                                  textColor:
                                      Standard.colorFFFFFF.withOpacity(.82)),
                              Container(
                                width: 379.w,
                                height: 34.h,
                                margin: setEdgeInsets(left: 22),
                                color: Colors.brown,
                              )
                            ],
                          ),
                        ),
                        Padding(
                          padding: setEdgeInsets(top: 14),
                          child: Row(
                            children: [
                              text(
                                  textString: '设备名称',
                                  textSize: 14.sp,
                                  textColor:
                                      Standard.colorFFFFFF.withOpacity(.82)),
                              Container(
                                width: 379.w,
                                height: 34.h,
                                margin: setEdgeInsets(left: 8),
                                color: Colors.brown,
                              )
                            ],
                          ),
                        ),
                        Padding(
                          padding: setEdgeInsets(top: 14),
                          child: Row(
                            children: [
                              text(
                                  textString: '所属门店',
                                  textSize: 14.sp,
                                  textColor:
                                      Standard.colorFFFFFF.withOpacity(.82)),
                              Container(
                                width: 379.w,
                                height: 34.h,
                                margin: setEdgeInsets(left: 8),
                                color: Colors.brown,
                              )
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                  Padding(
                    padding: setEdgeInsets(top: 40),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.end,
                      children: [
                        Container(
                          width: 88.w,
                          height: 34.h,
                          color: HexColor('#414146'),
                          child: Center(
                            child: text(
                                textString: '取消',
                                textColor:
                                    Standard.colorFFFFFF.withOpacity(.82),
                                textSize: 14.sp),
                          ),
                        ),
                        Container(
                          margin: setEdgeInsets(left: 24),
                          width: 88.w,
                          height: 34.h,
                          color: HexColor('#1C3EF3'),
                          child: Center(
                            child: text(
                                textString: '提交',
                                textColor:
                                    Standard.colorFFFFFF.withOpacity(.82),
                                textSize: 14.sp),
                          ),
                        ),
                      ],
                    ),
                  )
                ],
              ),
            ),
          );
        },
      );
}
